package scanner.impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import pojo.Customer;
import scanner.DataScanner;

public class DataScannerImpl implements DataScanner {
	private InputStream in;
	private Scanner scaner;
	
	public DataScannerImpl(InputStream in) {
		super();
		this.in = in;
		scaner=new Scanner(in);
		
	}

	public List<Customer> scann() {
		List<String> list=preScan("regexpr");
		List<Customer> list1=new ArrayList<Customer>();
		String reg="\\s+";
		for(String s:list){
			String[] ss=s.split(reg);
			Customer c=new Customer();
			InfFilter inf=new InfFilter();
			c.setId(inf.getId(ss[0]));
			c.setName(inf.getName(ss[1]));
			c.setEmail(inf.getMail(ss[2]));
			c.setSex(inf.getSex(ss[3]));
			c.setBirth(inf.getBirthday(ss[4]));	
			list1.add(c);
		}		
		return list1;
	}
	private List<String> preScan(String reg){
		List<String> list=new ArrayList<String>();
		while(scaner.hasNext()){
			list.add(scaner.nextLine());
		}
		return list;
	}
	
	
	

}
